/*
 * @Author: wuqingchun
 * @Date: 2024-07-16 10:25:08
 * @Description: 时间戳获取工具定义
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-07-16 10:26:22
 */

#ifndef __MEM_TIME_H__
#define __MEM_TIME_H__

#include <sys/time.h>

// 精度为纳秒的时间戳
#define TIMESTAMP_NOW_NS(nts) do {\
    struct timespec __ts;\
    (void)clock_gettime(CLOCK_REALTIME, &__ts);\
    nts = (unsigned long)__ts.tv_sec * 1000000000lu + (unsigned long)__ts.tv_nsec;\
} while (0)

//精度为微秒的时间戳
#define TIMESTAMP_NOW_US(usecs) do {\
    struct timeval __tv;\
    (void)gettimeofday(&__tv, NULL);\
    usecs = __tv.tv_sec * 1000000lu + (unsigned long)__tv.tv_usec;\
}while (0)

#endif //__MEM_TIME_H__
